package com.iwdnb.gkgz.application.service.router.strategyTradeStatistic;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.iwdnb.gkgz.common.model.dto.StrategyTradeDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

/**
 * 按均线统计
 */
@Service
@Slf4j
public class PeriodStrategyTradeStatisticService extends BaseStrategyTradeStatisticService {

    @Override
    public Map<String, List<StrategyTradeDTO>> statisticTradeList(String group, String parentGroup,
        List<StrategyTradeDTO> strategyTradeList) {
        if (CollectionUtils.isEmpty(strategyTradeList)) {
            return null;
        }
        Map<String, List<StrategyTradeDTO>> map = strategyTradeList.stream().collect(
            Collectors.groupingBy(groupFunction));
        return formatStatisticMap(group, parentGroup, map);
    }

    Function<StrategyTradeDTO, String> groupFunction = tradeDTO -> tradeDTO.getV11().intValue() + "";
}
